<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");
require_once("userFunction.php");

$errMsg = "";
$uid = sxREQUEST("uid");
$pwd = sxREQUEST("pwd");
$name = sxREQUEST("name");
$last_name = sxREQUEST("last_name");
$authenticaz = sxREQUEST("authenticaz");
$mobile_phone = sxREQUEST("mobile_phone");
$e_mail = sxREQUEST("e_mail");
$phone = sxREQUEST("phone");

if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "save"){
	$errMsg .= userIns();	
}

//output HTML
$aOpz = array("tit2"=>_t("Nuovo utente"), "isReloadable"=>$isReloadable);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/ajax.js"></script>  
<script language="JavaScript" type="text/javascript">
	function objFrmSave(){
		var errMsg = "";
		var objFrm = document.getElementById("objFrm");
		var objMessArea =  document.getElementById("messArea");
		
		var obj =  document.getElementById("uid");
		if(obj.value == ""){
			errMsg += "<?php echo _t("Lo user name &egrave; obbligatorio")?>.<br>";
			obj.className = "inpt01";
			obj.focus();
		}else{
			obj.className = "inpt01";
		}
		var obj =  document.getElementById("pwd");
		if(obj.value == ""){
			errMsg += "<?php echo _t("La password &egrave; obbligatoria")?>.<br>";
			obj.className = "inpt01";
			obj.focus();
		}else{
			obj.className = "inpt01";
		}
		if(errMsg == ""){
			objFrm.submit();
		}else{
			objMessArea.innerHTML = errMsg;
		}		
	}
</script>
  
<?php
echo(bodyHTML($aOpz));
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
//form inserimento dati
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"userIns.php\" method=\"POST\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"xsn\" id=\"xsn\" value=\"".XSN."\">");
//output comandi
$aCmd = array("ins"=>array("pag"=>"javascript:objFrmSave()",
										"title"=>_t("inserisci un nuovo utente"),
										"text"=>_t("salva"),
										"perm"=>"newuser"),
					"back"=>array("pag"=>$objUser->getHistory(0,false),
										"title"=>$objUser->getHistoryText(0),
										"text"=>$objUser->getHistoryText(0))
					);
echo(commandsHTML($aCmd));	
echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan=\"2\">"._t("Utente")."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width=\"20%\">"._t("nome utente")."*</td>" .
			"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"uid\" id=\"uid\" maxlength=\"128\" size=\"32\" value=\"".sxHE($uid)."\"></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("password")."*</td>" .
			"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"pwd\" id=\"pwd\" maxlength=\"128\" size=\"32\" value=\"".sxHE($pwd)."\"></td>" .
		"</tr>\n");
echo("<tr>" .
	"<td class=\"labl01\">"._t("nome")."</td>" .
	"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"name\" id=\"name\" value=\"".sxHE($name)."\"></td>" .
"</tr>\n");
echo("<tr>" .
	"<td class=\"labl01\">"._t("cognome")."</td>" .
	"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"last_name\" id=\"last_name\" value=\"".sxHE($last_name)."\"></td>" .
"</tr>\n");
echo("<tr>" .
		"<td class=\"labl01\">"._t("autenticreqtype")."</td>" .
		"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"authenticaz\" id=\"authenticaz\"  size=\"32\" value=\"".sxHE($authenticaz)."\"></td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"labl01\">"._t("telefono cellulare")."</td>" .
		"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"mobile_phone\" id=\"mobile_phone\" value=\"".sxHE($mobile_phone)."\"></td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"labl01\">"._t("e-mail")."</td>" .
		"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"e_mail\" id=\"e_mail\"  size=\"32\" value=\"".sxHE($e_mail)."\"></td>" .
	"</tr>\n");
echo("<tr>" .
		"<td class=\"labl01\">"._t("telefono fisso")."</td>" .
		"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"phone\" id=\"phone\" value=\"".sxHE($phone)."\"></td>" .
	"</tr>\n");
echo("</table>");

echo(commandsHTML($aCmd));echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
$objSDAO->close();
?>
